package com.u17;


/**
 * @author u17
 * https://leetcode-cn.com/problems/plus-one/
 */
public class Solution {

    public int[] plusOne(int[] digits) {
        for (int i = digits.length - 1; i >= 0; i--) {
            if (digits[i] == 9) {
                digits[i] = 0;
            } else {
                digits[i]++;
                return digits;
            }
        }

        digits = new int[digits.length + 1];
        digits[0] = 1;
        return digits;
    }


    public static void main(String[] args) {
        int[] digits = new int[]{99};
        Solution solution = new Solution();
        int[] ints = solution.plusOne(digits);
        for (int x : ints) {
            System.out.println(x);
        }
    }
}
